package com.chaos.auth.service;

import com.chaos.auth.api.dto.MenuBtnDto;
import com.chaos.auth.api.dto.MenuDto;
import com.chaos.framework.model.dto.ID;
import com.chaos.framework.model.dto.page.PageList;
import com.chaos.framework.model.dto.page.PageQueryDto;
import com.chaos.framework.model.entity.Table;
import com.chaos.framework.model.helper.ConvertHelper;
import com.chaos.framework.model.helper.PageHelper;
import com.chaos.auth.entity.RbacMenuBtn;
import com.chaos.auth.api.data.RbacMenuBtnData;
import com.chaos.auth.mapper.RbacMenuBtnMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Jacky.Cui
 * @since 2024-11-13
 */
@Slf4j
@Component
public class RbacMenuBtnService extends ServiceImpl<RbacMenuBtnMapper, RbacMenuBtn> {

    public ID insertModel(RbacMenuBtnData data) {
        RbacMenuBtn entity = ConvertHelper.convert(data, RbacMenuBtn.class);
        return save(entity) ? new ID(entity.getId()) : null;
    }

    public boolean deleteModel(ID data) {
        return removeById(data.getId());
    }

    public boolean updateModelByID(RbacMenuBtnData data) {
        RbacMenuBtn entity = ConvertHelper.convert(data, RbacMenuBtn.class);
        return update(entity, new UpdateWrapper<RbacMenuBtn>().eq(Table.ID, data.getId()));
    }

    public RbacMenuBtnData selectByID(ID data) {
        return ConvertHelper.convert(getOne(new QueryWrapper<RbacMenuBtn>().eq(Table.ID, data.getId())), RbacMenuBtnData.class);
    }

    public List<RbacMenuBtnData> selectByData(RbacMenuBtnData data) {
        QueryWrapper<RbacMenuBtn> query = new QueryWrapper();
        query.orderByDesc(Table.ID);
        return ConvertHelper.convert(list(query), RbacMenuBtnData.class);
    }

    public PageList<RbacMenuBtnData> selectByPage(PageQueryDto<RbacMenuBtnData> pageData) {
        QueryWrapper<RbacMenuBtn> query = new QueryWrapper();
        query.orderByDesc(Table.ID);
        return PageHelper.pageList(page(PageHelper.page(pageData), query), RbacMenuBtnData.class);
    }

    public List<MenuBtnDto> getBtnList(List<MenuDto> menuDtoList) {
        return null;
    }
}
